package com.wits.qso.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.impl.BaseDaoImpl;
import com.wits.qso.dao.custom.CourseDaoCustom;
import com.wits.qso.entity.BtableH;
import com.wits.qso.entity.CList;
import com.wits.qso.entity.Course;

@Component
public class CourseDaoImpl extends BaseDaoImpl<Course, String> implements CourseDaoCustom
{

	/**
	 * 获取全部可用课表
	 */
	public List<BtableH> findEnableBtableH() {
		String strSql = " select * from qso_btable_h ";
		return em.createNativeQuery( strSql, BtableH.class ).getResultList();
	}

	public int resetListId(String cLstId) {
		Query query = em.createQuery( "UPDATE Course o SET o.listId = null WHERE o.listId.id = :cLstId" );
		query.setParameter( "cLstId", cLstId );

		return query.executeUpdate();
	}

	public List<Course> findByLst(CList clst) {
		Query query = em.createQuery( "FROM Course o WHERE o.listId = :clst" );
		query.setParameter( "clst", clst );
		
		return query.getResultList();
	}
	
	public Course findByTitle(String title) {
		Query query = em.createQuery( "FROM Course o WHERE o.title = :title" );
		query.setParameter( "title", title );
		
		return (Course) query.getSingleResult();
	}
	
	public List<Course> findUnKnowLst() {
		return em.createQuery( "FROM Course o WHERE o.listId IS NULL" ).getResultList();		
	} 
}
